package com.lockdemo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class MyService{
	private Lock lock = new ReentrantLock();
	public void testMethod(){
		lock.lock();
		for(int i=0; i<5; i++){
			System.out.println("ThreadName="+Thread.currentThread().getName()+"  "+(i+1));
		}
		lock.unlock();
	}
}
class MyThread extends Thread{
	private MyService myService;

	public MyThread(MyService myService) {
		super();
		this.myService = myService;
	}
	@Override
	public void run() {
		myService.testMethod();
	}
	
}
public class Run1 {

	public static void main(String[] args) {
		MyService myService = new MyService();
		MyThread a1 = new MyThread(myService);
		MyThread a2 = new MyThread(myService);
		MyThread a3 = new MyThread(myService);
		MyThread a4 = new MyThread(myService);
		MyThread a5 = new MyThread(myService);
		
		a1.start();
		a2.start();
		a3.start();
		a4.start();
		a5.start();
	}

}
